import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class smallchangesOOP {

    boolean loop = true;
    Scanner myscanner = new Scanner(System.in);
    String key = "";
    String details = "----------------零钱通明细----------------";//拼接零钱通明细
    double money = 0;
    double balance = 0;
    Date date = null;
    SimpleDateFormat format_date = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    double reduce = 0;
    String note = "";
    public void fn1(){
        System.out.println(details);
    }
    public void fn2(){
        if(money < 0){
            System.out.println("收益必须大于零");
        }else{
            System.out.print("请输入你的收益:");
            money = myscanner.nextDouble();
            balance += money;
            date = new Date();

            details += "\n收益入账\t\t\t" + money + "\t" + format_date.format(date) + "\t" + "余额：" + balance;
        }
    }
    public void fn3(){
        if(money < 0){
            System.out.println("输入正数即可");
        }else{
            System.out.print("请输入你的消费情况说明:");
            note = myscanner.next();
            System.out.print("请输入你的消费金额：");
            reduce = myscanner.nextDouble();
            balance -= reduce;
            date = new Date();

            details += "\n" + note + "\t\t\t" + balance + "\t" + format_date.format(date) + "\t" + "余额：" + balance;
        }
    }
    public void fn4(){
        System.out.println("4.退出");
        loop = false;
    }
    public void menu(){
        do{
            System.out.println("===========零钱通菜单===========");
            System.out.println("\t\t\t1.零钱通明细");
            System.out.println("\t\t\t2.收益入账");
            System.out.println("\t\t\t3.消费");
            System.out.println("\t\t\t4.退出");

            System.out.print("请选择（1--4）：");
            key = myscanner.next();
            switch(key){
                case "1":
                     this.fn1();
                    break;
                case "2":
                     this.fn2();
                    break;
                case "3":
                    this.fn3();
                    break;
                case "4":
                     this.fn4();
                    break;
                default:
                    System.out.println("输入有误，请重新尝试");

            }
        }while(loop);
        System.out.println("-----------退出了零钱通服务-----------");
    }
}
